// ignore_for_file: avoid_init_to_null

/*
 * @Author: CodeHare
 * @Date: 2023-11-20 14:19:16
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-04-24 17:32:53
 * @Description: 报障单列表
 */

import 'package:get/get.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/utils/enums.dart';

class FaultReportListState {
  final RefreshController refreshController = RefreshController();
  List<FaultReportItemModel> dataList = [];

  dynamic id = null;
  List<int?> siteIds = [];
  String startTime = "";
  String endTime = "";
  int pageNum = 1;
  int pageSize = 10;
  dynamic status = null;
  String hintText = ResKey.workOrderSearchHint.tr;
  bool hasMore = true;
  bool get isNoData {
    if (dataList.isNotEmpty) {
      return false;
    } else {
      return true;
    }
  }
}

class FaultReportItemModel {
  dynamic address;
  dynamic closeTime;
  String? content;
  dynamic createBy;

  ///报单时间
  String? createTime;
  int? createUser;
  String? creatName;
  int? current;
  dynamic descPicUrl;
  dynamic description;
  dynamic email;
  dynamic endTime;
  int? handlerBy;
  String? handlerName;

  ///工单编号，示例：84
  int? id;
  dynamic maintenanceTask;

  ///故障标题
  String? name;
  dynamic objId;
  int? orgId;
  String? orgName;
  int? pageSize;
  String? phone;
  dynamic picture;
  dynamic processTime;
  String? remark;
  dynamic service;
  int? siteId;
  dynamic siteIds;

  ///站点名称
  String? siteName;
  int? source;
  dynamic sourceId;
  dynamic startTime;

  ///工单状态 0-待处理（已申报）1-维修中 3-维修完成 6-完成
  ReportTaskStatusType? status;
  dynamic tails;
  dynamic taskTailId;
  String? timeOfAppointment;

  ///install(0, "安装工单"),
  int? type;
  dynamic updateBy;
  dynamic updateName;
  String? updateTime;
  dynamic updateUser;
  int? userId;
  String? userName;

  FaultReportItemModel({
    this.address,
    this.closeTime,
    this.content,
    this.createBy,
    this.createTime,
    this.createUser,
    this.creatName,
    this.current,
    this.descPicUrl,
    this.description,
    this.email,
    this.endTime,
    this.handlerBy,
    this.handlerName,
    this.id,
    this.maintenanceTask,
    this.name,
    this.objId,
    this.orgId,
    this.orgName,
    this.pageSize,
    this.phone,
    this.picture,
    this.processTime,
    this.remark,
    this.service,
    this.siteId,
    this.siteIds,
    this.siteName,
    this.source,
    this.sourceId,
    this.startTime,
    this.status,
    this.tails,
    this.taskTailId,
    this.timeOfAppointment,
    this.type,
    this.updateBy,
    this.updateName,
    this.updateTime,
    this.updateUser,
    this.userId,
    this.userName,
  });

  factory FaultReportItemModel.fromJson(Map<String, dynamic> json) =>
      FaultReportItemModel(
        address: json["address"],
        closeTime: json["closeTime"],
        content: json["content"],
        createBy: json["createBy"],
        createTime: json["createTime"],
        createUser: json["createUser"],
        creatName: json["creatName"],
        current: json["current"],
        descPicUrl: json["descPicUrl"],
        description: json["description"],
        email: json["email"],
        endTime: json["endTime"],
        handlerBy: json["handlerBy"],
        handlerName: json["handlerName"],
        id: json["id"],
        maintenanceTask: json["maintenanceTask"],
        name: json["name"],
        objId: json["objId"],
        orgId: json["orgId"],
        orgName: json["orgName"],
        pageSize: json["pageSize"],
        phone: json["phone"],
        picture: json["picture"],
        processTime: json["processTime"],
        remark: json["remark"],
        service: json["service"],
        siteId: json["siteId"],
        siteIds: json["siteIds"],
        siteName: json["siteName"],
        source: json["source"],
        sourceId: json["sourceId"],
        startTime: json["startTime"],
        status:
            $enumDecodeNullable($ReportTaskStatusTypeEnumMap, json['status']),
        tails: json["tails"],
        taskTailId: json["taskTailId"],
        timeOfAppointment: json["timeOfAppointment"],
        type: json["type"],
        updateBy: json["updateBy"],
        updateName: json["updateName"],
        updateTime: json["updateTime"],
        updateUser: json["updateUser"],
        userId: json["userId"],
        userName: json["userName"],
      );

  Map<String, dynamic> toJson() => {
        "address": address,
        "closeTime": closeTime,
        "content": content,
        "createBy": createBy,
        "createTime": createTime,
        "createUser": createUser,
        "creatName": creatName,
        "current": current,
        "descPicUrl": descPicUrl,
        "description": description,
        "email": email,
        "endTime": endTime,
        "handlerBy": handlerBy,
        "handlerName": handlerName,
        "id": id,
        "maintenanceTask": maintenanceTask,
        "name": name,
        "objId": objId,
        "orgId": orgId,
        "orgName": orgName,
        "pageSize": pageSize,
        "phone": phone,
        "picture": picture,
        "processTime": processTime,
        "remark": remark,
        "service": service,
        "siteId": siteId,
        "siteIds": siteIds,
        "siteName": siteName,
        "source": source,
        "sourceId": sourceId,
        "startTime": startTime,
        "status": status,
        "tails": tails,
        "taskTailId": taskTailId,
        "timeOfAppointment": timeOfAppointment,
        "type": type,
        "updateBy": updateBy,
        "updateName": updateName,
        "updateTime": updateTime,
        "updateUser": updateUser,
        "userId": userId,
        "userName": userName,
      };
}

class FaultReportListReqParams {
  /// 页数
  int? current;

  /// 当前页条数
  int? pageSize;

  /// 开始时间
  String? startTime;

  ///结束时间
  String? endTime;

  /// 站点ids
  List<int?>? siteIds;

  /// 工单状态
  /// 0-待处理（已申报）1-维修中 3-维修完成 6-完成
  int? status;

  /// 工单号
  dynamic id;

  FaultReportListReqParams({
    this.current,
    this.endTime,
    this.pageSize,
    this.siteIds,
    this.startTime,
    this.status,
    this.id,
  });

  factory FaultReportListReqParams.fromJson(Map<String, dynamic> json) =>
      FaultReportListReqParams(
        current: json["current"],
        endTime: json["endTime"],
        pageSize: json["pageSize"],
        siteIds: json["siteIds"],
        startTime: json["startTime"],
        status: json["status"],
        id: json["id"],
      );

  Map<String, dynamic> toJson() => {
        "current": current,
        "endTime": endTime,
        "pageSize": pageSize,
        "siteIds": siteIds,
        "startTime": startTime,
        "status": status,
        "id": id,
      };
}
